<div id="wrap">
	<div class="title"><?php echo $self['title']?></div>
	<div class="main">
		<div class="list">
			<div class="tt" id="action">
				<span>被举报的帖子</span>
				<select id="zone">
				<?php if($list){
				foreach($list as $item){ ?>
					<option value="<?php echo $item['cid']?>">帖子id:<?php echo $item['cid']?></option>
				<?php } 
				}else{ ?>
					<option value="0">无</option>
				<?php } ?>
				</select>
				<?php if($list){ ?>
				<span class="btn" id="del">删除该非法帖</span>
				<b style="color:#000">|</b>
				<span class="btn" id="ok">设为合法帖</span>
				<?php } ?>
			</div>
			<ul id="page"></ul>
			<table class="content">
				<thead>
					<tr><th>帖子id</th><th>标题</th><th>举报人</th><th>举报原因</th><th>时间</th></tr>
				</thead>
				<tbody id="tbody">
			
				</tbody>
			</table>
		</div>
	</div>
</div>
<script type="text/javascript">
  function ajax(url,fun){
  	let xmlhttp = new XMLHttpRequest();
  	xmlhttp.onreadystatechange = fun;
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
  }
  let tbody = document.getElementById('tbody');
  let page = document.getElementById('page');
  let zone = document.getElementById('zone');
  let action = document.getElementById('action');
  ajax("report_page.php?id="+zone.value,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  
  zone.onchange = function(){
  	ajax("report_page.php?id="+this.value,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  }
  
  page.onclick = function(e){
  	let href = e.target.getAttribute('href');
  	if(!/page=\d+/.test(href)){
  		return
  	}
  	ajax(href,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  	return false;
  }
  action.onclick = function(e){
  	let id = e.target.getAttribute('id');
  	if(id != 'del' && id != 'ok'){
  		return
  	}
  	if(confirm('您确定要执行这项操作吗?')){
  		let num = id == 'del'?4:3;
	  	ajax(`ud.php?type=${num}&id=${zone.value}`,function() {
		    if(this.readyState==4 && this.status==200) {
		    	let {res} = JSON.parse(this.response);
		      	if(res){
		      		window.location.reload();
		      	}
		    }
	  	});
  	}
  	
  }
</script>
</body>
</html>